package com.zdp.剑指offer;

import com.zdp.util.ListNode;

public class 反转链表 {
    public static void main(String[] args) {
        反转链表 demo = new 反转链表();
        ListNode list = ListUtil.createList(15);
        ListUtil.outList(list);
        list = demo.ReverseList(list);
        ListUtil.outList(list);
    }
    public ListNode ReverseList(ListNode head) {
        ListNode p = head;
        ListNode pre = null;
        while(p!=null){
            ListNode next = p.next;
            p.next = pre;
            pre = p;
            p = next;
        }
        return pre;
    }
}
